<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="门店" prop="deptId">
        <el-select v-model="queryParams.deptId" placeholder="请选择门店" clearable >
          <el-option
            v-for="item in slectDeptOptions"
            :key="item.deptId"
            :label="item.deptName"
            :value="item.deptId">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="销售员">
        <el-select v-model="queryParams.userId" placeholder="请选择销售员" clearable >
            <el-option
              v-for="item in slectUserOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
      </el-form-item>

      <el-form-item label="班次" prop="classes">
        <el-select v-model="queryParams.classes" placeholder="请选择班次" clearable>
          <el-option
            v-for="dict in dict.type.class"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="盘点日期" prop="checkTime">
        <el-date-picker clearable
          style="width: 240px"
          v-model="daterangeCheckTime"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd"
          placeholder="请选择盘点日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:checkService:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:checkService:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:checkService:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:checkService:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading"  show-summary :data="checkServiceList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="id" align="center" prop="id" /> -->
      <!-- <el-table-column label="门店id" align="center" prop="deptId" /> -->
      <el-table-column label="门店" align="center" width="120" prop="deptName" />
      <el-table-column label="班次" align="center" prop="classes">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.class" :value="scope.row.classes"/>
        </template>
      </el-table-column>
      <el-table-column label="销售员" align="center" prop="sellName" />
      <el-table-column label="电彩销售金额" width="120" align="center" prop="dcSaleMoney" />
      <el-table-column label="电彩销售数量" width="120" align="center" prop="dcSaleNum" />
      <el-table-column label="电彩兑奖金额" width="120" align="center" prop="dcConversionMoney" />
      <el-table-column label="竞彩销售金额" width="120" align="center" prop="jcSaleMoney" />
      <el-table-column label="竞彩销售数量" width="120" align="center" prop="jcSaleNum" />
      <el-table-column label="即开兑奖金额" width="120" align="center" prop="jkConversionMoney" />
      <!-- <el-table-column label="电子兑奖金额" align="center" prop="dzConversionMoney" /> -->
      <el-table-column label="移动支付金额" width="120" align="center" prop="ydPay" />
      <!-- <el-table-column label="移动支付未出票且入额度款" align="center" prop="ydUnBill" />
      <el-table-column label="吃票额度/手续费返还" align="center" prop="commissionRefund" /> -->
      <!-- <el-table-column label="电表数值" align="center" prop="spreadsheet" /> -->
      <el-table-column label="即开票下单金额" width="140" align="center" prop="jkOrderAmount" />
      <el-table-column label="盘点日期" align="center" prop="checkTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.checkTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:checkService:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:checkService:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改盘点--业务数据对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="门店" prop="deptId">
          <el-select v-model="form.deptId" placeholder="请选择门店">
            <el-option
              v-for="item in slectDeptOptions"
              :key="item.deptId"
              :label="item.deptName"
              :value="item.deptId">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="班次" prop="classes">
          <el-radio-group v-model="form.classes">
            <el-radio
              v-for="dict in dict.type.class"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="销售员" prop="sellId">
          <el-select v-model="form.sellId" placeholder="请选择销售员">
            <el-option
              v-for="item in slectUserOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="电彩销售" prop="dcSaleMoney">
              <el-input v-model="form.dcSaleMoney"  type="number" placeholder="请输入电彩销售金额" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="" prop="dcSaleNum">
              <el-input placeholder=""  type="number" v-model="form.dcSaleNum">
                <template slot="append">张</template>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>


        <el-form-item label="电彩兑奖金额" prop="dcConversionMoney">
          <el-input v-model="form.dcConversionMoney"  type="number" placeholder="请输入电彩兑奖金额" />
        </el-form-item>
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="竞彩销售" prop="jcSaleMoney">
              <el-input v-model="form.jcSaleMoney"  type="number" placeholder="请输入竞彩销售金额" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="" prop="jcSaleNum">
              <el-input placeholder=""  type="number" v-model="form.jcSaleNum">
                <template slot="append">张</template>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="即开兑奖金额" prop="jkConversionMoney">
          <el-input v-model="form.jkConversionMoney"  type="number" placeholder="请输入即开兑奖金额" />
        </el-form-item>

        <el-form-item label="移动支付金额" prop="ydPay">
          <el-input v-model="form.ydPay"   type="number" placeholder="请输入移动支付金额" />
        </el-form-item>

        <el-form-item label="即开票下单金额" prop="jkOrderAmount">
          <el-input v-model="form.jkOrderAmount"  type="number" placeholder="请输入即开票下单金额" />
        </el-form-item>
        <el-form-item label="盘点日期" prop="checkTime">
          <el-date-picker clearable
            v-model="form.checkTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择盘点日期">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCheckService, getCheckService, delCheckService, addCheckService, updateCheckService } from "@/api/system/checkService";
import { listDept } from "@/api/system/dept";
import { getSalesUserByUserName } from "@/api/system/user";
export default {
  name: "CheckService",
  dicts: ['class'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 盘点--业务数据表格数据
      checkServiceList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        deptId: null,
        dcSaleMoney: null,
        dcSaleNum: null,
        dcConversionMoney: null,
        jcSaleMoney: null,
        jcSaleNum: null,
        jkConversionMoney: null,
        dzConversionMoney: null,
        ydPay: null,
        ydUnBill: null,
        commissionRefund: null,
        spreadsheet: null,
        jkOrderAmount: null,
        checkTime: null,
      },
      slectDeptOptions:[],
      slectUserOptions:[],
      daterangeCheckTime:[],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询盘点--业务数据列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeCheckTime && '' != this.daterangeCheckTime) {
        this.queryParams.params["beginCheckTime"] = this.daterangeCheckTime[0];
        this.queryParams.params["endCheckTime"] = this.daterangeCheckTime[1];
      }
      listCheckService(this.queryParams).then(response => {
        this.checkServiceList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
      listDept({"parentId":100}).then(response => {
        this.slectDeptOptions = response.data;
      });
      getSalesUserByUserName({"userName":""}).then(response => {
        this.slectUserOptions = response.data;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        deptId: null,
        dcSaleMoney: null,
        dcSaleNum: null,
        dcConversionMoney: null,
        jcSaleMoney: null,
        jcSaleNum: null,
        jkConversionMoney: null,
        dzConversionMoney: null,
        ydPay: null,
        ydUnBill: null,
        commissionRefund: null,
        spreadsheet: null,
        jkOrderAmount: null,
        checkTime: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加业务数据";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getCheckService(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改业务数据";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCheckService(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCheckService(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除盘点--业务数据编号为"' + ids + '"的数据项？').then(function() {
        return delCheckService(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/checkService/export', {
        ...this.queryParams
      }, `checkService_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
